package com.platform.controller;

import java.util.List;
import java.util.Map;

import com.platform.cache.J2CacheUtils;
import com.platform.util.Constants;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.entity.IncomeCoinConfigEntity;
import com.platform.service.IncomeCoinConfigService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

/**
 * 发币配置类Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2019-02-02 02:05:50
 */
@RestController
@RequestMapping("incomecoinconfig")
public class IncomeCoinConfigController {
    @Autowired
    private IncomeCoinConfigService incomeCoinConfigService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("incomecoinconfig:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<IncomeCoinConfigEntity> tIncomeCoinConfigList = incomeCoinConfigService.queryList(query);
        int total = incomeCoinConfigService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(tIncomeCoinConfigList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("incomecoinconfig:info")
    public R info(@PathVariable("id") Long id) {
        IncomeCoinConfigEntity tIncomeCoinConfig = incomeCoinConfigService.queryObject(id);

        return R.ok().put("tIncomeCoinConfig", tIncomeCoinConfig);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("incomecoinconfig:save")
    public R save(@RequestBody IncomeCoinConfigEntity tIncomeCoinConfig) {
        incomeCoinConfigService.save(tIncomeCoinConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("incomecoinconfig:update")
    public R update(@RequestBody IncomeCoinConfigEntity tIncomeCoinConfig) {
        int result = incomeCoinConfigService.update(tIncomeCoinConfig);
        if (result > 0) {
            J2CacheUtils.remove(Constants.REDIS_COIN_CACHE ,Constants.REDIS_COIN_CONFIG+ tIncomeCoinConfig.getType());
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("incomecoinconfig:delete")
    public R delete(@RequestBody Long[] ids) {
        incomeCoinConfigService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<IncomeCoinConfigEntity> list = incomeCoinConfigService.queryList(params);

        return R.ok().put("list", list);
    }
}
